{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <div class='userinfo'>
        {include file="public/userleft"}
        <div class="pub_task">
            <h5>{:__('我成功的案例')}</h5>
            <ul class="layui-tab-title">
                <dl class="search">
                    <span>{:__('任务类型')}:</span><select class="layui-input types"><option>{:__('请选择任务类型')}</option><option>{:__('悬赏任务')}</option></select>
                    <span>{:__('标题')}:</span><input id="title" class="layui-input title" autocomplete="off" type="text"/>
                    <span>{:__('时间')}:</span>
                    <input id="time_s" class="layui-input time" placeholder="{:__('年-月-日')}" readonly type="text"/>-
                    <input id="time_e" class="layui-input time" placeholder="{:__('年-月-日')}" readonly type="text"/>
                    <button class='layui-btn layui-btn-primary' id="search">{:__('查询')}</button>
                </dl>
            </ul>
            <ul class="task_table">
                <dl><span>{:__('任务编号')}</span><span>{:__('任务类型')}</span><span>{:__('任务标题')}</span><span>{:__('任务金额')}</span><span>{:__('发布时间')}</span><span>{:__('状态')}</span><span>{:__('操作')}</span></dl>
            </ul>
        </div>
    </div>
    <div id="in_page" style="margin-left: 23%;"></div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    var status = 4;
    noLog();

    var lang = $.cookie("think_lang");
    var setlang = '';
    if(lang == 'en-us'){
        setlang = 'en';
    } else if(lang == 'zh-cn'){
        setlang= 'cn';
    }
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
            elem: '#time_s', //指定元素
            lang:setlang
        });
        
    });

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
            elem: '#time_e', //指定元素
            lang:setlang
        });
    });

    var total = 0;
    function gettask(newpage,status)
    {
        var title = $("#title").val();
        var time_s = $("#time_s").val();
        var time_e = $("#time_e").val();
        $.ajax({
            url:'/api/mission/mySuccess',
            type:'get',
            data:{'token':token,'page':newpage,'limit':5,title:title,time_s:time_s,time_e:time_e},
            success:function(ret){
                if(ret.code == 1){
                    $("._list").remove();
                    if(ret['data'] == '' && ret['data'] == null && ret['data'] == undefined){
                        return fasle;
                    }
                    if(ret['data']['ls'] == '' && ret['data']['ls'] == null && ret['data']['ls'] == undefined){
                        return fasle;
                    }
                    var htl = "";
                    for(i in ret['data']['ls']){
                        var status = "";
                        var option = "";
                        if(ret['data']['ls'][i]['status'] == 1){
                            status = '{:__("待付款")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a><a class="_edit" data-target="'+ret['data']['ls'][i]['mission_id']+'">{:__("编辑")}</a><a data-target="'+ret['data']['ls'][i]['mission_id']+'" class="_pay">{:__("付款")}</a><a class="_del">{:__("删除")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 2){
                            status = '{:__("待审核")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 3){
                            status = '{:__("进行中")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 4){
                            status = '{:__("完成")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 5){
                            status = '{:__("仲裁中")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        }
                        if(ret['data']['ls'][i]['mission_no'] == '' || ret['data']['ls'][i]['mission_no'] =='' || ret['data']['ls'][i]['mission_no'] == undefined){
                            ret['data']['ls'][i]['mission_no'] = '';
                        }
                        if(ret['data']['ls'][i]['title'] == '' || ret['data']['ls'][i]['title'] == '' || ret['data']['ls'][i]['title'] == undefined){
                            ret['data']['ls'][i]['title'] = '';
                        }
                        htl += '<dl class="_list">'
                            +'<span>'+ret['data']['ls'][i]['mission_no']+'</span>'
                            +'<span>{:__("悬赏任务")}</span>'
                            +'<span>'+ret['data']['ls'][i]['title']+'</span>'
                            +'<span>'+ret['data']['ls'][i]['money']+'</span>'
                            +'<span>'+ret['data']['ls'][i]['create_time']+'</span>'
                            +'<span>'+status+'</span>'
                            +'<span>'+option+'</span>'
                            +'</dl>';
                    }
                    $(".task_table").append(htl);
                    total = ret['data']['total'];
                    if(newpage == 1){
                        pagechange();
                    }
                   
                } else if(ret.code != 401){
                    layer.msg(ret.msg,{icon:2});
                }
            }
        });
    }
    $(document).on("click",".lookdetail",function(){
        var _this = $(this);
        var url = _this.attr("data-target");
        window.location.href="/"+url;
    });
    function pagechange()
    {
        //分页
        createpage('in_page',total,5,function(obj,first){
            var nowpage = obj.curr;
            if(!first){
                gettask(nowpage,status);
            }
        });
    }
    $(document).queue('task',function(){
        gettask(1,status);
    });
    $(document).dequeue('task');
    $(document).on("click",'.pub_task .layui-tab-title li',function(){
        var _this = $(this);
        status = _this.attr("data-target");
        gettask(1,status);
    });
    $("#search").click(function(){
        gettask(1,status)
    });
</script>